import java.util.Arrays;
import java.util.Scanner;

public class test4 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(); // 数组长度
        int[] num = new int[n];
        for (int i = 0; i < n; i++) {
            num[i] = in.nextInt();
        }
        System.out.println(Arrays.toString(moveZeroes(num)));
    }
    public static int[] moveZeroes(int[] num){
        // 使用双指针
        int start=0; // 开头
        int end = start+1; //零结尾 start和end之间都是为0
        int flag;
        while (end<num.length){
            if (num[start]==0&&num[end]!=0){
                //交换
                flag=num[start];
                num[start] = num[end];
                num[end] = flag;
            } else if (num[start]==0&&num[end]==0){
                // end 向后移7动
                end++;
                continue;
            }
            start++;
            end++;
        }
        return num;
    }
}
